# KRTS内核层代码
project(Kernel)

# 设置策略CMP0091为NEW，新策略 用于MT/MD等编译选项的配置
if(POLICY CMP0091)
    cmake_policy(SET CMP0091 NEW)
endif(POLICY CMP0091)

include_directories(.)
include_directories(..)

# 配置生成的执行文件、静态库、动态库保存位置
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BUILD_LIB_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BUILD_LIB_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BUILD_BIN_DIR})

set(LUA_LIST
        ../3rdparty/lua-5.4.7/lapi.c
        ../3rdparty/lua-5.4.7/lapi.h
        ../3rdparty/lua-5.4.7/lauxlib.c
        ../3rdparty/lua-5.4.7/lauxlib.h
        ../3rdparty/lua-5.4.7/lbaselib.c
        ../3rdparty/lua-5.4.7/lcode.c
        ../3rdparty/lua-5.4.7/lcode.h
        ../3rdparty/lua-5.4.7/lcorolib.c
        ../3rdparty/lua-5.4.7/lctype.c
        ../3rdparty/lua-5.4.7/lctype.h
        ../3rdparty/lua-5.4.7/ldblib.c
        ../3rdparty/lua-5.4.7/ldebug.c
        ../3rdparty/lua-5.4.7/ldebug.h
        ../3rdparty/lua-5.4.7/ldo.c
        ../3rdparty/lua-5.4.7/ldo.h
        ../3rdparty/lua-5.4.7/ldump.c
        ../3rdparty/lua-5.4.7/lfunc.c
        ../3rdparty/lua-5.4.7/lfunc.h
        ../3rdparty/lua-5.4.7/lgc.c
        ../3rdparty/lua-5.4.7/lgc.h
        ../3rdparty/lua-5.4.7/linit.c
        ../3rdparty/lua-5.4.7/liolib.c
        ../3rdparty/lua-5.4.7/ljumptab.h
        ../3rdparty/lua-5.4.7/llex.c
        ../3rdparty/lua-5.4.7/llex.h
        ../3rdparty/lua-5.4.7/llimits.h
        ../3rdparty/lua-5.4.7/lmathlib.c
        ../3rdparty/lua-5.4.7/lmem.c
        ../3rdparty/lua-5.4.7/lmem.h
        ../3rdparty/lua-5.4.7/loadlib.c
        ../3rdparty/lua-5.4.7/lobject.c
        ../3rdparty/lua-5.4.7/lobject.h
        ../3rdparty/lua-5.4.7/lopcodes.c
        ../3rdparty/lua-5.4.7/lopcodes.h
        ../3rdparty/lua-5.4.7/lopnames.h
        ../3rdparty/lua-5.4.7/loslib.c
        ../3rdparty/lua-5.4.7/lparser.c
        ../3rdparty/lua-5.4.7/lparser.h
        ../3rdparty/lua-5.4.7/lprefix.h
        ../3rdparty/lua-5.4.7/lstate.c
        ../3rdparty/lua-5.4.7/lstate.h
        ../3rdparty/lua-5.4.7/lstring.c
        ../3rdparty/lua-5.4.7/lstring.h
        ../3rdparty/lua-5.4.7/lstrlib.c
        ../3rdparty/lua-5.4.7/ltable.c
        ../3rdparty/lua-5.4.7/ltable.h
        ../3rdparty/lua-5.4.7/ltablib.c
        ../3rdparty/lua-5.4.7/ltm.c
        ../3rdparty/lua-5.4.7/ltm.h
        #../3rdparty/lua-5.4.7/lua.c
        ../3rdparty/lua-5.4.7/lua.h
        ../3rdparty/lua-5.4.7/lua.hpp
        #../3rdparty/lua-5.4.7/luac.c
        ../3rdparty/lua-5.4.7/luaconf.h
        ../3rdparty/lua-5.4.7/lualib.h
        ../3rdparty/lua-5.4.7/lundump.c
        ../3rdparty/lua-5.4.7/lundump.h
        ../3rdparty/lua-5.4.7/lutf8lib.c
        ../3rdparty/lua-5.4.7/lvm.c
        ../3rdparty/lua-5.4.7/lvm.h
        ../3rdparty/lua-5.4.7/lzio.c
        ../3rdparty/lua-5.4.7/lzio.h
)

# 链接库
if (MSVC)
    # 配置忽略库
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -NODEFAULTLIB:oldnames.lib")

    if(CMAKE_BUILD_TYPE MATCHES "Debug")
        set(BUG_POSTFIX "d")
    else()
        set(BUG_POSTFIX "")
    endif()
endif ()

# 生成动态库
add_library(${PROJECT_NAME} SHARED
        kernel.cpp
        Base/SharedData.h
        Base/Kithara.cpp
        Business/TaskHandle.cpp
        Business/TaskHandle.h
        ${LUA_LIST}
        Business/PluginManagement.cpp
        Business/PluginManagement.h
        Business/KitharaPluginBase.h
)

# 配置生成库头文件路径
target_include_directories(${PROJECT_NAME}
        PUBLIC ${KITHARA_INCLUDE_SMP}
        PUBLIC ${KITHARA_INCLUDE}
)

# 链接依赖库
if(WIN32)
    target_link_libraries(${PROJECT_NAME} PUBLIC
            ${KITHARA_LIB}
    )
endif()

# 设置MT/MTd
set_property(TARGET ${PROJECT_NAME} PROPERTY
        MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

# 设置编译选项
if (MSVC)
    set_target_properties(${PROJECT_NAME} PROPERTIES
            COMPILE_FLAGS "/EHsc"
    )
endif ()